package com.payment.controller;


import com.payment.entity.Arrange;
import com.payment.entity.ArrangeWithDoctorDto;
import com.payment.service.ArrangeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;


@CrossOrigin
@RestController
@RequestMapping("/arrange")  //排班
public class ArrangeController {

    @Resource
    private ArrangeService arrangeService;

    @GetMapping("/getAll")  //查询所有医生的排班信息
    public ResponseEntity<ResDTO> getAll() {

        List<ArrangeWithDoctorDto> _list = arrangeService.getAll();
        if (_list!=null){
            return ResponseEntity.ok(ResDTO.success(_list));
        }else {
            return ResponseEntity.ok(ResDTO.error());
        }
    }

    @GetMapping("/getByKeyword/{keyword}") //通过医生姓名查询排班信息
    public ResponseEntity<ResDTO> getByKeyword(@PathVariable String keyword){
        List<ArrangeWithDoctorDto> _list = arrangeService.getByKeyword(keyword);
        if (_list.size()>0){
            return ResponseEntity.ok(ResDTO.success(_list));
        }else {
            return ResponseEntity.ok(ResDTO.error("查询失败！请重新输入医生姓名！"));
        }
    }

    @PostMapping("/addArrange")
    public  ResponseEntity<ResDTO> add(@RequestBody Arrange entity){
        System.out.println("///////////");
        System.out.println(entity);
        int res = arrangeService.add(entity);
        if (res>0){
            return ResponseEntity.ok(ResDTO.success(null));
        }else {
            return ResponseEntity.ok(ResDTO.error("添加失败！"));
        }
    }

    @PutMapping("/putArrange/{id}")
    public ResponseEntity<ResDTO> update(@PathVariable int id,@RequestBody Arrange entity){
        entity.setId(id);
        int res = arrangeService.update(entity);
        if (res>0){
            return ResponseEntity.ok(ResDTO.success(null));
        }else {
            return ResponseEntity.ok(ResDTO.error());
        }
    }

    @DeleteMapping("/delArrange/{id}")
    public ResponseEntity<ResDTO> del(@PathVariable int id){
        int res = arrangeService.del(id);
        if (res>0){
            return ResponseEntity.ok(ResDTO.success(null));
        }else {
            return ResponseEntity.ok(ResDTO.error());
        }
    }
}
